<?php
echo $this->headScript()->setFile($this->baseUrl().'/js/jquery/table-sorter/jquery.dataTables.js');
$permission_arr = array('edit_enable' => $this->allow('edit','backendgateway','Paymentgateway'), 'publish_enable' => $this->allow('publish','backendgateway','Paymentgateway'));
?>
<script type="text/javascript">
$(document).ready(function() {

	$('a.up_btn').click(function() {
		var self = this;				
		var arr = $(self).attr('rel').split('_');		
		var prev_order = $(self).parents("td:first").children("input:nth-child(1)").val();		
		$.ajax({
				 url: "<?php echo $this->url( array('module'=> 'Paymentgateway', 'controller' => 'backendgateway', 'action'     => 'up' ), 'adminrout',    true) ?>",
				 type: 'POST',
				 data: { article_id: arr[0], order: prev_order},
				 beforeSend: function(){
					$(self).html('<img src="application/modules/Administrator/layouts/scripts/images/tools/up-animation.gif" border="0" />');
				 },
				 success: function(response) 
				 {
				 	//alert(response);
					var json_arr = eval("("+response+")");
					if(json_arr.status == 'ok')
					{
						$(self).parents("td:first").children("input:nth-child(1)").val((prev_order-1));
						if(json_arr.id_arr != '' && json_arr.id_arr != null)
						{
							for(var i = 0; i < json_arr.id_arr.length; i++)
							{
								for(var j=0;j < $('a.up_btn').length ;j++)
								{
									var arrUp = $('a.up_btn:eq('+j+')').attr('rel').split('_');									
									if(arrUp[0] == json_arr.id_arr[i])	
									{										
										$('a.up_btn:eq('+j+')').parents("td:first").children("input:nth-child(1)").val(prev_order);
									}					
								}
							}							
						}						
					}
					else
					{
						openMsgDialog(json_arr.msg);
					}
					$(self).html('<img src="application/modules/Administrator/layouts/scripts/images/tools/up-arrow.gif" border="0" />');
				 }
			});
	});	
	
	$('a.down_btn').click(function() {
		var self = this;				
		var arr = $(self).attr('rel').split('_');		
		var prev_order = $(self).parents("td:first").children("input:nth-child(1)").val();		
		
		$.ajax({
				 url: "<?php echo $this->url( array('module'=> 'Paymentgateway', 'controller' => 'backendgateway', 'action'     => 'down' ), 'adminrout',    true) ?>",
				 type: 'POST',
				 data: { article_id: arr[0], order: prev_order},
				 beforeSend: function(){
					$(self).html('<img src="application/modules/Administrator/layouts/scripts/images/tools/down-animation.gif" border="0" />');
				 },
				 success: function(response) 
				 {
				 	// alert(response);
					var json_arr = eval("("+response+")");
					if(json_arr.status == 'ok')
					{
						var new_order = parseInt(prev_order) + 1;
						$(self).parents("td:first").children("input:nth-child(1)").val(new_order);
						if(json_arr.id_arr != '' && json_arr.id_arr != null)
						{
							for(var i = 0; i < json_arr.id_arr.length; i++)
							{
								for(var j=0;j < $('a.up_btn').length ;j++)
								{
									var arrUp = $('a.up_btn:eq('+j+')').attr('rel').split('_');									
									if(arrUp[0] == json_arr.id_arr[i])	
									{										
										$('a.up_btn:eq('+j+')').parents("td:first").children("input:nth-child(1)").val(prev_order);
									}					
								}
							}							
						}						
					}
					else
					{
						openMsgDialog(json_arr.msg);
					}
					$(self).html('<img src="application/modules/Administrator/layouts/scripts/images/tools/down-arrow.gif" border="0" />');
				 }
			});
	});
	
	
	$('a.all_order_btn').click(function() {
		var self = this;
		var order_str = '';
		var article_id_str = '';
		for(var i=0;i<$('input.order_text').length;i++)
		{
			if(i == 0)
			{
				order_str += $('input.order_text:eq('+i+')').val();
				article_id_str += $('input.order_text:eq('+i+')').parents("td:first").children("a:first").attr('rel');
			}
			else
			{
				order_str += ','+$('input.order_text:eq('+i+')').val();
				article_id_str += ','+$('input.order_text:eq('+i+')').parents("td:first").children("a:first").attr('rel');
			}
		}
		
		$.ajax({
				 url: "<?php echo $this->url( array('module'=> 'Paymentgateway', 'controller' => 'backendgateway', 'action'     => 'orderall' ), 'adminrout',    true) ?>",
				 type: 'POST',
				 data: { article_id_arr: article_id_str, order_arr: order_str},
				 beforeSend: function(){
				 	oTable.fnSettings().aoColumns[4].bSortable = false;
					$(self).html('<img src="application/modules/Administrator/layouts/scripts/images/loader/ajax_loader.gif" height="16" border="0" />');
				 },
				 success: function(response) 
				 {
				 	//alert(response);
					var json_arr = eval("("+response+")");
					openMsgDialog(json_arr.msg);
					$(self).html('<img src="application/modules/Administrator/layouts/scripts/images/tools/save.png" border="0" />');
					oTable.fnSettings().aoColumns[4].bSortable = true;
				 }
		});
	});
		
	floatingbar('#floatingbar',"#button_top_bar",null);	
		
	/****************************Sorting Table Start*********************/
	var oTable = $("#sortTable").dataTable({
				"bPaginate": false,
				"bLengthChange": true,
				"bSearchable": true,
				"bFilter": true,
				"bSort": true,
				"bInfo": false,
				"bAutoWidth": true,
				"bProcessing": false,
				"bSortClasses": true,
				"bStateSave": false,
				"bServerSide": false,
				"aaSorting": [[ 0, "asc" ]],				
				"aoColumnDefs": [ 
						{ "bSortable": false, "bSortClasses": false,  "aTargets": [ 1, 3 ] }
					],
				"oLanguage" : { "sSearch": "<?php echo $this->translator->translator('jquery_filter'); ?>" }
			}); 	
	
	$('td', oTable.fnGetNodes()).hover( function() {		
		$(this).parents("tr:first").children('td').addClass( 'highlighted' );
	}, function() {
		$('td.highlighted').removeClass('highlighted');
	} );
	
	/****************************Sorting Table End*********************/
	
		function openMsgDialog(msg)
		{
			$('#dialog_container').html(msg).dialog({
						autoOpen: true,
						modal: false,
						show: 'fade',
						resizable: 'false',				
						buttons: { "<?php echo html_entity_decode($this->translator->translator('common_ok'), ENT_QUOTES, "UTF-8"); ?>": function() { $(this).dialog('option', 'hide', 'explode').dialog("close"); } },
						open: function(event, ui)
							 {
								setTimeout(function() 
								{									
									if($('#' + event.target.id).dialog('isOpen'))
									{
										$('#' + event.target.id).dialog('option', 'hide', 'explode').dialog('close');										
									}
								}, 10000);
							  }
					});
		}
			
	$('a.dafault_btn').click(function() {
		var self = this;				
		var arr = $(self).attr('rel');
		var hrf = $(self).attr('href');
		if(hrf != null)
		{
			$(self).html('<img src="application/modules/Administrator/layouts/scripts/images/loader/ajax_loader.gif" height="16" border="0" />');
			$.ajax({
				 url: "<?php echo $this->url( array('module'=> 'Paymentgateway', 'controller' => 'backendgateway', 'action'     => 'setdefault' ), 'adminrout',    true) ?>",
				 type: 'POST',
				 data: { id: arr},
				 success: function(response) 
				 {
					var json_arr = eval("("+response+")");
					if(json_arr.status == 'ok')
					{						
						$('a.dafault_btn').html('<img src="application/modules/Administrator/layouts/scripts/images/tools/undefault.gif" border="0" title="<?php echo $this->translator->translator("gateway_undefaulted_title"); ?>" />');
						$('a.dafault_btn').attr('href','javascript: void(0)');						
						
						$(self).html('<img src="application/modules/Administrator/layouts/scripts/images/tools/default.gif" border="0" title="<?php echo $this->translator->translator("gateway_defaulted_title"); ?>" />');
						$(self).removeAttr("href");					
					}
					else
					{
						openMsgDialog(json_arr.msg);
						$(self).html('<img src="application/modules/Administrator/layouts/scripts/images/tools/undefault.gif" border="0" title="<?php echo $this->translator->translator("gateway_undefaulted_title"); ?>" />');
					}
				 }		
			});
		}
	});
	
	$('a.publish_btn').click(function() {
		var self = this;		
		<?php if ($permission_arr['publish_enable']){ ?>
			var arr = $(self).attr('rel').split('_');		
			$.ajax({
				 url: "<?php echo $this->url( array('module'=> 'Paymentgateway', 'controller' => 'backendgateway', 'action'     => 'publish' ), 'adminrout',    true) ?>",
				 type: 'POST',
				 data: { id: arr[0], payment_name: arr[1], paction: arr[2]},
				 beforeSend: function(){
						$(self).html('<img src="application/modules/Administrator/layouts/scripts/images/loader/ajax_loader.gif" border="0" height="17" />');
					 },
				 success: function(response) 
				 {
					//alert(response);
					var json_arr = eval("("+response+")");
					if(json_arr.status == 'ok')
					{
						if(json_arr.active == '1')
						{
							$(self).html('<img src="application/modules/Administrator/layouts/scripts/images/tools/published.gif" border="0" title="<?php echo $this->translator->translator("common_unpublish_title"); ?>" alt="<?php echo $this->translator->translator("common_unpublish_title"); ?>" />').attr('rel',arr[0]+"_"+arr[1]+"_unpublish");
						}
						else
						{
							$(self).html('<img src="application/modules/Administrator/layouts/scripts/images/tools/unpublished.gif" border="0" title="<?php echo $this->translator->translator("common_publish_title"); ?>" alt="<?php echo $this->translator->translator("common_publish_title"); ?>" />').attr('rel',arr[0]+"_"+arr[1]+"_publish");
						}
					}
					else
					{
						openMsgDialog(json_arr.msg);
						if(json_arr.active == '1')
						{
							$(self).html('<img src="application/modules/Administrator/layouts/scripts/images/tools/unpublished.gif" border="0" title="<?php echo $this->translator->translator("common_publish_title"); ?>" alt="<?php echo $this->translator->translator("common_publish_title"); ?>" />').attr('rel',arr[0]+"_"+arr[1]+"_publish");
							
						}
						else
						{
							$(self).html('<img src="application/modules/Administrator/layouts/scripts/images/tools/published.gif" border="0" title="<?php echo $this->translator->translator("common_unpublish_title"); ?>" alt="<?php echo $this->translator->translator("common_unpublish_title"); ?>" />').attr('rel',arr[0]+"_"+arr[1]+"_unpublish");
						}
					}
				 }
			});
		<?php }else{ ?>
			var msg = "<?php echo $this->translator->translator('common_publish_perm'); ?>";
				openMsgDialog(msg);
		<?php } ?>
	});	
	
/************************************************IMAGE THUMBNIL************************************************/
	$("span.thumb").hover(function() {
		$(this).css({'z-index' : '10'}); /*Add a higher z-index value so this image stays on top*/ 
		$(this).find('img').addClass("hover").stop() /* Add class of "hover", then stop animation queue buildup*/
			.animate({
				marginTop: '-30px', /* The next 4 lines will vertically align this image */ 
				marginLeft: '-5px',
				top: '50%',
				left: '50%',
				width: '174px', /* Set new width */
				height: '64px', /* Set new height */
				padding: '8px'
			}, 200); /* this value of "200" is the speed of how fast/slow this hover animates */
	
		} , function() {
		$(this).css({'z-index' : '0'}); /* Set z-index back to 0 */
		$(this).find('img').removeClass("hover").stop()  /* Remove the "hover" class , then stop animation queue buildup*/
			.animate({
				marginTop: '-8px', /* Set alignment back to default */
				marginLeft: '8px',
				top: '0',
				left: '0',
				width: '100px', /* Set width back to default */
				height: '28px', /* Set height back to default */
				padding: '5px'
			}, 400);
	});
	
	
});
</script>

<div id="container">
<?php if (!$this->allow()) : ?>
	<div class="grid_12 t_a_bottom">
		<?php echo $this->translator->translator('Member_Access_deny_desc'); ?>
	</div>
<?php else : ?>

<div class="title-container">
	<div class="gateways"><h1><?php echo $this->translator->translator('gateway_list_page_name'); ?></h1></div>
</div>
<div id="button_top_bar"></div>
<div class="content-container">
	<div id="sidebar-inner">
    	<?php echo $this->partial('backendgateway/nav_menu.phtml');  ?>
    </div>
    
    
    <div id="content-inner">
    	<div class="pagination">
        	<?php echo $this->paginationControl($this->datas, 'Sliding', 'top_pagination.phtml'); ?>
        </div>
        
        <div class="chart">
            <div class="data-table">
            	<table id="sortTable" width="100%" align="center" cellpadding="0" cellspacing="0">
              		<thead>
                		<tr>
                  			<th width="6%"><?php echo $this->translator->translator('gateway_list_page_id'); ?></th>
                  			<th width="14%"><?php echo $this->translator->translator('gateway_list_page_logo'); ?> </th>
                  			<th width="45%"><?php echo $this->translator->translator('gateway_list_page_title'); ?> </th>
                  			<th width="15%">
                            	<?php echo $this->translator->translator('common_order'); ?>
                              	<a href="javascript: void(0);" class="all_order_btn"><img src="application/modules/Administrator/layouts/scripts/images/tools/save.png" border="0" /></a>												
                  			</th>
                  			<th width="11%"><?php echo $this->translator->translator('common_status'); ?></th>
                  			<th width="9%"><?php echo $this->translator->translator('common_action'); ?></th>
                		</tr>
              		</thead>
                    
                  	<tbody>
                    <?php 
                    $mem_db = new Members_Model_DbTable_MemberList();
                    $j = 1;
                    $parentInfo = array();
                    foreach ($this->datas as $entry): 
                        if($j % 2 == 0)
                        {
                            $onmouseout = "this.bgColor='#FFFFFF';";
                            $background = '#FFFFFF';
                        }
                        else
                        {
                            $onmouseout = "this.bgColor='#F7F7F7';";
                            $background = '#F7F7F7';
                        }
                    ?>
                   		<tr bgcolor="<?php echo $background; ?>" onmouseover="this.bgColor='#FCF5DD';" onmouseout="<?php echo $onmouseout; ?>">
                      		<td class="center"><?php echo $this->escape($entry->id); ?></td>
                      		<td class="center"><?php if($this->escape($entry->logo) != '') { ?><span class="thumb"><img src="data/frontImages/gateway/gateway_logo/<?php echo $this->escape($entry->logo); ?>" width="100" height="28" class="payment-gateway"/></span><?php } ?></td>
                      		<td class="center"><?php echo $this->escape($entry->title); ?></td>
                      		<td class="center">
                        		<input type="text" size="1" name="order" id="order" class="order_text" value="<?php echo $this->escape($entry->payment_order); ?>" />
                               	<a href="javascript: void(0);" rel="<?php echo $this->escape($entry->id); ?>" class="up_btn"><img src="application/modules/Administrator/layouts/scripts/images/tools/up-arrow.gif" border="0" /></a>&nbsp;<a href="javascript: void(0);" rel="<?php echo $this->escape($entry->id); ?>" class="down_btn"><img src="application/modules/Administrator/layouts/scripts/images/tools/down-arrow.gif"  border="0" /></a>
                      		</td>
                      		<td class="center"><a href="javascript:void(0);" class="publish_btn" rel="<?php echo $this->escape($entry->id); ?>_<?php echo str_replace('_',' ',$this->escape($entry->name)); ?>_<?php if($this->escape($entry->active) == '1'){ ?>unpublish<?php }else{ ?>publish<?php } ?>"><?php if($this->escape($entry->active) == '1'){ ?><img src="application/modules/Administrator/layouts/scripts/images/tools/published.gif" border="0" title="<?php echo $this->translator->translator('common_unpublish_title'); ?>" alt="<?php echo $this->translator->translator('common_unpublish_title'); ?>" /><?php }else{ ?><img src="application/modules/Administrator/layouts/scripts/images/tools/unpublished.gif"  border="0" title="<?php echo $this->translator->translator('common_publish_title'); ?>" alt="<?php echo $this->translator->translator('common_publish_title'); ?>" /><?php } ?></a></td>
                      		<td class="center">
                           		<?php if ($permission_arr['edit_enable']) : ?>
                                	<a href="<?php echo $this->url( array('module'=> 'Paymentgateway', 'controller' => 'backendgateway', 'action'     => $this->escape(strtolower($entry->name)), 'id' => $this->escape($entry->id)), 'adminrout',    true) ?>"><img src="application/modules/Administrator/layouts/scripts/images/tools/edit.png" title="<?php echo $this->translator->translator('common_edit_title'); ?>" border="0" /></a>
                                <?php endif; ?>                                                       
							</td>
                    	</tr>
                    <?php 													
                        $j++;
                        endforeach;
                  	?>
                  	</tbody>
				</table>
            </div>
		</div>
        
        <div class="pagination">
        	<?php echo $this->paginationControl($this->datas, 'Sliding', 'pagination.phtml'); ?>
        </div>
	</div>    
</div>

<div id="floatingbar">
	<h1><?php echo $this->translator->translator('gateway_list_page_name'); ?></h1>
</div>
<?php endif; ?>

<div id="dialog_container" title="<?php echo $this->translator->translator('common_dialog_msg',$this->translator->translator('gateway_list_page_name')); ?>"></div>
<div id="dialog-confirm" title="<?php echo $this->translator->translator('common_confirmation',$this->translator->translator('common_delete')); ?>"></div>
</div>